<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-touch-fullscreen" content="yes">
		<meta name="format-detection" content="telephone=no;email=no">
		<title>index</title>

	</head>

	<body>
		<script src="js/mui.min.js"></script>
		<script src="js/common.js"></script>
		<script>
			mui.init({
				preloadPages: [{
						url: "main.html",
						id: "main",
						show: {
							aniShow: 'none'
						}
				}]
			});
			mui.plusReady(function() {
				var isClick = false; //是否触发click事件
				plus.push.addEventListener("click", function(msg) {
					isClick = true;
					//ios离线推送时监听click事件
					plus.runtime.setBadgeNumber(0); //清除程序快捷方式上显示的提示数字
					var newsId = msg.payload.newsId;
					var type = msg.payload.type;
					contentOpt(newsId, type);
				}, false);

				// 监听在线消息事件
				plus.push.addEventListener("receive", function(msg) {
					//接收到在线APNS消息 和 android通知消息中的透传消息
					var json = JSON.parse(msg.content);
					var newsId = json.newsId;
					var type = json.type;
					var title = json.title;
					//android进receive事件，说明content不符合规格...但是content是json格式啊...
					if(mui.os.ios) {
						if(isClick) {
							isClick = false;
						} else {
							mui.confirm(title, '为您推荐的新闻', btnArray, function(e) {
								if(e.index == 0) {
									contentOpt(newsId, type)
								}
							});
						}
					} else {
						contentOpt(newsId, type);
					}

				}, false);
				var btnArray = ['查看', '稍后查看'];

				function contentOpt(newsId, type) {
					plus.runtime.setBadgeNumber(0); //清除程序快捷方式上显示的提示数字
					var href = null;
					if(type == 1) {
						href = 'images-details.html';
					} 
					else if(type == 3){
						href = 'vote-details.html';
					}
					else {
						href = 'news-details.html';
					}
					//打开详情页面          
					mui.openWindow({
						url: './html/news/' + href,
						id: href,
						extras: {
							newsId: newsId
						},
						waiting: {
							autoShow: false
						},
						createNew: true //是否重复创建同样id的webview，默认为false:不重复创建，直接显示
					});
				}

				//读取本地存储，检查是否为首次启动
				var showGuide = plus.storage.getItem("lauchFlag");
				if(showGuide) {
					//有值，说明引导页已经显示过了，无需显示；
					//关闭splash页面；
					//plus.navigator.closeSplashscreen();
					//plus.navigator.setFullscreen(false);
					
					//显示广告页
					mui.ajax({
						url: baseUrl + '/devs/createUc?devicesId=' + plus.device.uuid,
						dataType: 'json',
						type: 'get',
						success: function(data) {
							if (data.returnFlag == 0) {
								var src = data.actions[0].carouselImage;
								plus.storage.setItem("ad", src);
								//显示广告页
								mui.openWindow({
									url: 'lauch/banner.html',
									id: 'banner',
									show: {
										aniShow: 'none'
									},
									waiting: {
										autoShow: false
									}
								});
							}
						},
						error: function(xhr, type, errorThrown) {
							//异常处理
						}
					});
				} else {
					//显示启动导航
					mui.openWindow({
						url: 'lauch/guide.html',
						id: 'guide',
						show: {
							aniShow: 'none'
						},
						waiting: {
							autoShow: false
						}
					});
				}
			});
		</script>
	</body>

</html>